package exercise.day10;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

public class 编程练习题 {

    /**
     * 一个用户，在一段时间内，做了很多的行为（用Event代表）
     * 现在，定义一个事件序列规则：  e1,e3,e5
     * 然后对一个用户的事件列表进行判断，如果他依次做过 序列中定义的所有事件，则返回3
     * 如果他依次做过 e1,e3 ，则返回2
     * 如果他依次做过e1  ，则返回1
     * 如果序列中的事件一个都没发生过，则返回0
     *
     * 注意： 判断用户的一个行为是否跟规则中的事件吻合，需要它们的eventid相等
     * 并且规则中事件的properties的kv值要与用户行为的一致
     *
     *
     * 功能： 从一个传入的 Event列表中，查找
     * @param args
     */



    public static void main(String[] args) {
        /**
         * 模拟生成一堆 事件
         */
        HashMap<String, String> props1 = new HashMap<>();
        props1.put("p1","v1");
        props1.put("p5","v5");
        Event e1 = new Event("e1",1,props1);

        HashMap<String, String> props2 = new HashMap<>();
        props2.put("p1","v2");
        props2.put("p5","v5");
        Event e2 = new Event("e1",2,props2);


        HashMap<String, String> props3 = new HashMap<>();
        props3.put("p1","v1");
        Event e3 = new Event("e2",2,props3);

        HashMap<String, String> props4 = new HashMap<>();
        props4.put("p3","v3");
        props4.put("p4","v4");
        Event e4 = new Event("e3",3,props4);

        HashMap<String, String> props5 = new HashMap<>();
        props5.put("p3","v3");
        props5.put("p4","v4");
        props5.put("px","vy");
        Event e5 = new Event("e5",4,props5);

        HashMap<String, String> props6 = new HashMap<>();
        props6.put("p4","v4");
        Event e6 = new Event("e4",5,props6);

        ArrayList<Event> events = new ArrayList<>();
        events.add(e1);
        events.add(e2);
        events.add(e3);
        events.add(e4);
        events.add(e5);
        events.add(e6);

        /**
         * 模拟定制要查询的事件序列
         */
        HashMap<String, String> prp1 = new HashMap<>();
        prp1.put("p1","v1");
        Event rule1 = new Event("e1",1,prp1);


        HashMap<String, String> prp2 = new HashMap<>();
        prp2.put("p4","v4");
        Event rule2 = new Event("e3",1,prp2);

        HashMap<String, String> prp3 = new HashMap<>();
        prp3.put("p4","v4");
        Event rule3 = new Event("e5",1,prp3);

        ArrayList<Event> rules = new ArrayList<>();
        rules.add(rule1);
        rules.add(rule2);
        rules.add(rule3);
    }
}

class Event {
    String eventid;
    long timeStamp;
    HashMap<String,String> properties;

    public Event(String eventid,long timeStamp, HashMap<String, String> properties) {
        this.eventid = eventid;
        this.timeStamp = timeStamp;
        this.properties = properties;
    }
}





